﻿using System;
using TradeHelp.Utilities;

namespace ConsoleDemo.Data
{
    public class Person
    {
        private string _toString;

        public Person(String name, int age, String occupation)
        {
            Invariant.CheckIsNullOrEmpty(name, "name");
            Invariant.CheckIsNullOrEmpty(occupation, "occupation");

            Name = name;
            Age = age;
            Occupation = occupation;
        }

        protected string Occupation { get; set; }

        public String Name { get; private set; }

        public Int32 Age { get; private set; }

        public override int GetHashCode()
        {
            return Name.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            return Equals(obj as Person);
        }

        public bool Equals(Person other)
        {
            if (other == null) return false;
            if (other.GetType() != GetType()) return false;
            return other.Name == Name;
        }

        public override string ToString()
        {
            if (_toString == null)
            {
                _toString = String.Format("{0} {1} {2}", Name, Age, Occupation);
            }
            return _toString;
        }
    }
}
